#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include <QTimer>
#include <QBluetoothDeviceDiscoveryAgent>       //设备搜寻
#include <QBluetoothLocalDevice>                //本地设备信息
#include <QMessageBox>                          //对话框
#include <QLowEnergyController>                 //设备连接
#include <QLowEnergyService>                    //数据接收、发送
#include <QLowEnergyCharacteristic>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_scanButton_clicked();

    void deviceDiscovered(const QBluetoothDeviceInfo &device);

    void on_tableWidget_itemSelectionChanged();

    void on_connectButton_clicked();

    void serviceDiscovered(const QBluetoothUuid &serviceUuid);
    void serviceScanDone();
    void writeCharacteristic();
    void characteristicRead(const QLowEnergyCharacteristic &info, const QByteArray &value);
    void characteristicChanged(const QLowEnergyCharacteristic &info, const QByteArray &value);
    void on_disconnButton_clicked();

private:
    Ui::MainWindow *ui;

    QTimer *gBarTimer;
    int     gBarVal;

    uint16_t gCurRow;
    uint16_t gCurCol;

    QLowEnergyController *controller;
    QLowEnergyService *service;
    QLowEnergyCharacteristic writeCharacteristics;
    QBluetoothDeviceDiscoveryAgent *discoveryAgent;
};
#endif // MAINWINDOW_H
